//
//  TranquilState.swift
//  HIextractLicve
//
//  Created by HIextractLicve on 2024/12/12.
//

import UIKit
import ProgressHUD

/// 私聊
class TranquilState: UIViewController {
    var mindfulness:Set<Int>?
    var suggestion:Set<String>?
    var  professionals:Set<CGFloat>?
    var exchangeHTLC:[String:Array<Dictionary<String,String>>]?

    var eachVioViewHTLC:THLCNOrBUTTOn?
    var mindfulnessPageHTL:THLCNPageControll?
    var journeyHTLC:UIView?
    
    var  passonHtlacData:Dictionary<String,String>
    init(stressdescHTL:Set<Int>,passonHtlacData: Dictionary<String, String>) {
        self.passonHtlacData = passonHtlacData
        super.init(nibName: nil, bundle: nil)
        mindfulness = [99]
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var listDialogsHTLC:Array<(Bool,String)> =  Array<(Bool,String)>()
    let tableviewrDatachatHTL = UITableView.init(frame: .zero, style: .plain)
    let texfieldChatHTL = UITextField.init()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if self.navigationController?.navigationBar.isHidden == true {
            journeyHTLC?.alpha = 1
            journeyHTLC?.layer.cornerRadius = 12
        }
        journeyHTLC?.backgroundColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)

        eachVioViewHTLC = THLCNOrBUTTOn.init()
        eachVioViewHTLC?.setTitle("anchors", for: .normal)
        if journeyHTLC != nil {
            journeyHTLC?.addSubview(eachVioViewHTLC ?? THLCNOrBUTTOn.init())
            view.addSubview(journeyHTLC!)
        }

        mindfulnessPageHTL = THLCNPageControll()
        mindfulnessPageHTL?.numberOfPages = 1
       
        
        view.backgroundColor =  UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 1)
        NotificationCenter.default.addObserver(self, selector: #selector(diBakissBoockHTLC), name: NSNotification.Name("htldeleteuser"), object: nil)
       
        let abacjkbroHTLC = UIButton.init()
        abacjkbroHTLC.addTarget(self, action: #selector(diBakissBoockHTLC), for: .touchUpInside)
        abacjkbroHTLC.setImage(UIImage.init(named: "graybackjHTL"), for: .normal)
        
        let avtheader = UIImageView(image: UIImage.init(named: passonHtlacData["HTLCAvater"] ?? ""))
        avtheader.layer.cornerRadius = 20
        avtheader.layer.masksToBounds = true
        avtheader.contentMode = .scaleToFill
        
        mindfulnessPageHTL?.backgroundColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)
        mindfulnessPageHTL?.tintColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)
        mindfulnessPageHTL?.sizeToFit()

        if journeyHTLC != nil {
            journeyHTLC?.addSubview(mindfulnessPageHTL ?? THLCNPageControll.init())
           
        }
        let titkelHTLC = UILabel.init()
        titkelHTLC.text = passonHtlacData["HTLCkiName"]
        titkelHTLC.textColor = .white
        titkelHTLC.font =  UIFont(name: "Trebuchet MS Bold", size: 14)
        titkelHTLC.textAlignment = .left
       
        let morebroHTLC = UIButton.init()
        morebroHTLC.addTarget(self, action: #selector(moreoperationBackHTLC), for: .touchUpInside)
        morebroHTLC.setImage(UIImage.init(named: "more_hometitle"), for: .normal)
        
        
        let callViewbuttonHTLC = UIButton.init()
        callViewbuttonHTLC.addTarget(self, action: #selector(callViewsdBackHTLC), for: .touchUpInside)
        callViewbuttonHTLC.setImage(UIImage.init(named: "callChatshipHtl"), for: .normal)
        
        
        tableviewrDatachatHTL.rowHeight = UITableView.automaticDimension
        tableviewrDatachatHTL.estimatedRowHeight = 44
        tableviewrDatachatHTL.contentInset = UIEdgeInsets.zero
        tableviewrDatachatHTL.register(HTLAIChanDetiklCell.self, forCellReuseIdentifier: "HTLAIChanDetiklCellID")
        tableviewrDatachatHTL.showsVerticalScrollIndicator = false
        tableviewrDatachatHTL.backgroundColor = .clear
     
            tableviewrDatachatHTL.dataSource = self
            tableviewrDatachatHTL.separatorStyle = .none
            tableviewrDatachatHTL.allowsSelection = false
            tableviewrDatachatHTL.delegate = self
            tableviewrDatachatHTL.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 120, right: 0)
            
            
        

       
      
        
        
       
        texfieldChatHTL.layer.masksToBounds = true
        texfieldChatHTL.textColor = .white
        texfieldChatHTL.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.1000)
        texfieldChatHTL.leftViewMode = .always
        texfieldChatHTL.leftView = UIView(frame: CGRect.init(x: 0, y: 0, width: 25.xHTL, height: 52.xHTL))
        texfieldChatHTL.rightViewMode = .always
        texfieldChatHTL.rightView = UIView(frame: CGRect.init(x: 0, y: 0, width: 24 + 8 + 12, height: 52.xHTL))
       
        texfieldChatHTL.layer.cornerRadius = 26.xHTL
        texfieldChatHTL.attributedPlaceholder = NSAttributedString.init(string: "Say something......", attributes: [NSAttributedString.Key.foregroundColor : UIColor.white])
        
        
        
        let postButtonhtlv = UIButton.init()
        postButtonhtlv.setImage(UIImage(named: "whitertSend"), for: .normal)
        
        postButtonhtlv.addTarget(self, action: #selector(staretSendMeadeNallHTLC), for: .touchUpInside)
        
        view.addSubview(abacjkbroHTLC)
        view.addSubview(avtheader)
        view.addSubview(titkelHTLC)
        view.addSubview(tableviewrDatachatHTL)
        view.addSubview(texfieldChatHTL)
        view.addSubview(postButtonhtlv)
        view.addSubview(callViewbuttonHTLC)
       
        abacjkbroHTLC.snp.makeConstraints { make in
            make.width.height.equalTo(32)
            make.leading.equalToSuperview().offset(12)
            make.top.equalToSuperview().offset(saaffeeTppoHightHTL + 8)
        }
        avtheader.snp.makeConstraints { make in
            make.width.height.equalTo(40)
            make.centerY.equalTo(abacjkbroHTLC)
            make.leading.equalTo(abacjkbroHTLC.snp.trailing).offset(10)
        }
        titkelHTLC.snp.makeConstraints { make in
            make.leading.equalTo(avtheader.snp.trailing).offset(6)
            make.centerY.equalTo(abacjkbroHTLC)
        }
       
        tableviewrDatachatHTL.snp.makeConstraints { make in
            make.bottom.leading.trailing.equalToSuperview()
            make.top.equalTo(titkelHTLC.snp.bottom).offset(30)
        }
         
    
        texfieldChatHTL.snp.makeConstraints { make in
            make.leading.equalToSuperview().inset(12)
            make.trailing.equalToSuperview().inset(68)
            make.height.equalTo(52)
            make.bottom.equalToSuperview().offset(-bommbsafeHeitHTL - 20)
        }
        
      
        
        postButtonhtlv.snp.makeConstraints { make in
            make.trailing.equalToSuperview().inset(68 + 24)
            make.height.width.equalTo(24)
            make.centerY.equalTo(texfieldChatHTL)
        }
        
        callViewbuttonHTLC.snp.makeConstraints { make in
            make.width.height.equalTo(44)
            make.trailing.equalToSuperview().inset(12)
            make.centerY.equalTo(texfieldChatHTL)
        }
        
    }
    
    @objc func moreoperationBackHTLC() {
        
        let Asvc = UIAlertController(title: HTLROOOMMeasg.BinrwetioBase64("UmVwb3J0aW5nIG9yIEJsb2Nr"), message:HTLROOOMMeasg.BinrwetioBase64("QXJlIHlvdSBzdXJlIHlvdSB3YW50IHRvIGJsb2NrIG9yIGJsYWNrbGlzdCB0aGlzIHVzZXI/IFNlbGVjdCB0aGUgb3BlcmF0aW9uIHlvdSB3YW50IHRvIGRvLiBBZnRlciB0aGUgdXNlciBpcyBibGFja2xpc3RlZCwgYWxsIHJlbGF0ZWQgaW5mb3JtYXRpb24gd2lsbCBubyBsb25nZXIgYmUgZGlzcGxheWVk") , preferredStyle:.actionSheet)
    
       
        let ActdeleBlock = UIAlertAction(title: HTLROOOMMeasg.BinrwetioBase64("QmxvY2s="), style: .default) { acvf in
            ProgressHUD.animate()
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                var huihuo = 43
                huihuo += 1
                var pagenorHTLC = 23
                pagenorHTLC -= 2
               
                ProgressHUD.succeed(HTLROOOMMeasg.BinrwetioBase64("VGhlIHVzZXIgaGFzIGJlZW4gYmxhY2tsaXN0ZWQh"), delay: 2.5)
                HTLCAllDealRelaxing.Relaxing.removeApplerlUserFrom(stressdescHTL: [33,222,444], WhoINfoHTL:self.passonHtlacData)
            }
           
        }
        
        let reportdeleBlock = UIAlertAction(title: HTLROOOMMeasg.BinrwetioBase64("UmVwb3J0"), style: .default) { acvf in
            self.navigationController?.pushViewController(UntentionSetting.init(), animated: true)
        }
        Asvc.addAction(ActdeleBlock)
      
            Asvc.addAction(reportdeleBlock)
        
        
        self.present(Asvc, animated: true)
    }
    
    @objc func diBakissBoockHTLC() {
       self.navigationController?.popToRootViewController(animated: true)
    }
    
    
    @objc func callViewsdBackHTLC() {
       
        self.navigationController?.pushViewController(MentalWellbeing.init(stressdescHTL: [222,333,444], passonHtlacData: self.passonHtlacData), animated: true)
    }

    @objc func staretSendMeadeNallHTLC()  {
      
       
        if let conted = texfieldChatHTL.text,
           conted.count != 0 {
            
            let diologdata = (true,conted)
            listDialogsHTLC.append(diologdata)
            
            
           
                texfieldChatHTL.text = nil
                texfieldChatHTL.resignFirstResponder()
               
            
            
            
            self.tableviewrDatachatHTL.reloadData()
            
            return
            
        }
            ProgressHUD.banner(HTLROOOMMeasg.BinrwetioBase64("RW1wdHkgY29udGVudCBjYW5ub3QgYmUgc2VuZA=="), nil, delay: 2.0)
          
            
        
    }
    
    
}


extension TranquilState:UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
     
        return listDialogsHTLC.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let Diversity = tableView.dequeueReusableCell(withIdentifier:"HTLAIChanDetiklCellID") as! HTLAIChanDetiklCell
        
        Diversity.duihuaLblHTLC.text = listDialogsHTLC[indexPath.row].1
        
       

        Diversity.updateCell_HTLCCellDiolog(stressdescHTL: [456,456,456], isfghjtBool: listDialogsHTLC[indexPath.row].0)
       
        return Diversity
    }
}
